package com.platform.usercenter.utils;

import com.platform.common.core.utils.DateUtils;
import com.platform.constants.SysUserConstants;

import java.time.DayOfWeek;
import java.time.LocalDate;
import java.time.temporal.ChronoUnit;
import java.util.ArrayList;
import java.util.List;

public class PlanRuleUtils {

	public static void main(String[] args) {
		String startDate = "2023-11-01";
		String endDate = "2023-12-31";
		String scheduleRule = "值一轮四"; // 排班规则

		List<String> result = calculateScheduleDates(startDate, endDate, scheduleRule);
		for (String date : result) {
			System.out.println(date);
		}
	}
	/**
	 * 计算排班日期
	 *
	 * @param startDate 开始日期（格式：YYYY-MM-DD）
	 * @param endDate   结束日期（格式：YYYY-MM-DD）
	 * @param schedule  排班规则（如：值1休2）
	 * @return 需要上班的日期列表
	 */
	public static List<String> calculateScheduleDates(String startDate, String endDate, String schedule) {
		String work=schedule.charAt( 1 )+"";
		String rest=schedule.charAt( 3 )+"";
		List<String> resultList = new ArrayList<>();
		LocalDate start = LocalDate.parse(startDate);
		LocalDate end = LocalDate.parse(endDate);

		int workDays =SysUserConstants.NUMBER_MAP.get( work );
		int restDays = SysUserConstants.NUMBER_MAP.get( rest );

		int days=0;
		LocalDate date = start;

		while (!date.isAfter(end)) {
			if (days%(workDays+restDays)<workDays) { // 判断是否需要上班
				resultList.add( date.toString());
			}
			days++;
			date = date.plusDays(1);
		}

		return resultList;
	}

}
